    {{define "infoCollection/inspection.html"}}
<div class="box box-info">
    <div class="box-header with-border">
        <h3 class="box-title">指导意见</h3>
        <button type="button"  id="newFD" class="btn btn-info">添加</button>
    </div>
    <table class="table table-hover">

    </table>
    <nav class="Page" aria-label="Page navigation">
        <ul class="pager">
            <li class="pre"><a class="disabled" onclick="pre()">上一页</a></li>
            <li class="next"><a class="disabled" onclick="next()">下一页</a></li>
        </ul>
    </nav>
</div>
<!-- Modal -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span>
                </button>
                <h4 class="modal-title" id="myModalLabel">指导意见</h4>
            </div>
            <div class="modal-body">
                <form class="form-horizontal" role="form" id="feedbackForm">
                    <div class="form-group">
                        <label for="recipient-name" class="control-label col-sm-2">姓名：</label>
                        <div class="col-sm-4">
                            <input type="text" class="form-control" readonly="true" name="_userName" id="_userName">
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="message-text" class="control-label col-sm-2">反馈意见：</label>
                        <div class="col-sm-10">
                            <textarea style="min-height: 100px;width:470px;" readonly="true" class="form-control" id="_feedC" name="_feedC"></textarea>
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="recipient-name" class="control-label col-sm-2">反馈时间：</label>
                        <div class="col-sm-4">
                            <input type="text" class="form-control" readonly="true" name="_feedTime" id="_feedTime">
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="recipient-name" class="control-label col-sm-2">指导医师：</label>
                        <div class="col-sm-4">
                            <input type="text" class="form-control" name="_guidePhysician" id="_guidePhysician">
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="message-text" class="control-label col-sm-2">指导意见：</label>
                        <div class="col-sm-10">
                            <textarea style="min-height: 100px;width:470px;" name="_replyContent" class="form-control" id="_replyContent"></textarea>
                        </div>
                    </div>
                    <div class="form-group">
                        <label for="recipient-name" class="control-label col-sm-2">指导时间：</label>
                        <div class="col-sm-4">
                            <div class="input-group date">
                                <div class="input-group-addon">
                                    <i class="fa fa-calendar"></i>
                                </div>
                                <input type="text" name="_replyTime" id="_replyTime" class="form-control pull-right">
                            </div>
                        </div>
                    </div>
                    <div class="form-group" style="display: none;">
                        <label for="message-text" class="control-label col-sm-2"></label>
                        <div class="col-sm-10">
                            <input type="text" class="form-control" name="_feedbackId" id="_feedbackId">
                        </div>
                    </div>
                    <div class="form-group" style="display: none;">
                        <label for="message-text" class="control-label col-sm-2"></label>
                        <div class="col-sm-10">
                            <input type="text" class="form-control" name="_phone" id="_phone">
                        </div>
                    </div>
                    <div class="form-group" style="display: none;">
                        <label for="message-text" class="control-label col-sm-2"></label>
                        <div class="col-sm-10">
                            <input type="text" class="form-control" name="_idCard" id="_idCard">
                        </div>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                <button type="button" class="btn btn-primary"  id="_feedSave"  onclick="feedBackSave()">保存</button>
            </div>
        </div>
    </div>
</div>
<style type="text/css">
    .table tr:last-child{
        border-bottom: 1px solid #f4f4f4;
    }
    .Page{
        padding: 10px;
    }
    .pager{
        text-align: right !important;
        padding-right: 100px !important;
    }

    .pager li>a{
        margin-right: 20px;
        border-radius: 6px;
        cursor: pointer;
        color: #333;
    }
    .disabled{
        background-color: #eee !important;
        color: #ddd !important;
        cursor: default !important;
    }
    .table>tbody>tr>td, .table>tbody>tr>th, .table>tfoot>tr>td, .table>tfoot>tr>th, .table>thead>tr>td, .table>thead>tr>th {
        padding: 10px !important;
    }
    #newFD{
        float: right;
        margin-right: 30px;
        padding: 6px 20px
    }
</style>
<script>
    var idCard = "";
    var currentPage = 1;//当前页数
    var pageCount = 0;//当前总页数
    var pageLimit = 10;//每页条数
    var phone = "";
    $(function() {
        if (canUpdate != null && canUpdate != undefined && !canUpdate) {
            $("#newFD").hide();
        }

        var InterNum = 0;
        var InterFunt = setInterval(function(){
            InterNum=InterNum+1;
            if(InterNum>4||$("#baseUserInfo_IdCard").text()!=""){
                clearInterval(InterFunt);
                if($("#baseUserInfo_IdCard").text()!=""){
                    idCard = $("#baseUserInfo_IdCard").text();
                    getData($("#baseUserInfo_IdCard").text(),1);
                }
            }
        },1000)
        //
        $("#newFD").click(function(){
            $("#_userName").val($("#baseInfo_UserName").text());
            $("#_phone").val(phone);
            $("#_idCard").val($("#baseUserInfo_IdCard").text());
            $("#myModal").modal('show');
        })
    })
    //
    function feedBackSave(){
        var fbsd = {};
        var fbst = $('#feedbackForm').serializeArray();
        $.each(fbst, function () {
            fbsd[this.name] = this.value;
        });
        var data = JSON.stringify(fbsd);
        $.post("/infoCollection/saveFeedbackCont",{data:data},function(r){
            if(r.code=="1"){
                $("#myModal").modal('hide');
                toastr.success("保存成功！", '提示', {
                        "progressBar": true,
                        "positionClass": "toast-top-center",
                        "timeOut": "5000",
                        "closeButton": true
                    });
                 getData(idCard,currentPage)
            }else{
                toastr.warning("保存失败！", '提示', {
                        "progressBar": true,
                        "positionClass": "toast-top-center",
                        "timeOut": "5000",
                        "closeButton": true
                    });
            }
        })
    }
    //
    function pre(){
        if(currentPage>1){
            getData(idCard,currentPage-1)
        }else{
            $(".pre a").addClass("disabled");
        }
    }
    //
    function next(){
        if(currentPage<pageCount){
            getData(idCard,currentPage+1)
        }else{
            $(".next a").addClass("disabled");
        }
    }
    //
    function showModal(t){
        var status = $(t).find("td:eq(7)").text();
        if(status=="已回复"){
            $("#_guidePhysician").attr("readonly",true);
            $("#_replyContent").attr("readonly",true);
            $("#_replyTime").attr("readonly",true);
            $("#_feedSave").hide();
        }else{
            $("#_guidePhysician").attr("readonly",false);
            $("#_replyContent").attr("readonly",false);
            $("#_replyTime").attr("readonly",false);
            $("#_feedSave").show();
        }
        $("#_feedbackId").val($(t).find("td:eq(0)").attr("dataid"));
        $("#_phone").val($(t).find("td:eq(0)").attr("dataphone"));
        $("#_idCard").val($(t).find("td:eq(0)").attr("dataidCard"));
        $("#_userName").val($(t).find("td:eq(1)").text());
        $("#_feedC").val($(t).find("td:eq(2)").attr("title"));
        $("#_feedTime").val($(t).find("td:eq(3)").text());
        $("#_guidePhysician").val($(t).find("td:eq(4)").text());
        $("#_replyContent").val($(t).find("td:eq(5)").attr("title"));
        $("#_replyTime").val($(t).find("td:eq(6)").text());
        $("#myModal").modal('show');
    }
    //
    function getData(idCard,pageNum){
        //获取数据
        $.post("/infoCollection/getAllFeedbacks",{idCard:idCard,pageNum:pageNum,pageLimit:pageLimit},function(r){
            if (r.data){
                currentPage = pageNum;
                pageCount = Math.ceil(r.code/pageLimit);
                if(pageCount>1&&currentPage!=pageCount){
                     $(".next a").removeClass("disabled");
                 }else{
                    $(".next a").addClass("disabled");
                }
                if(pageCount>1&&currentPage>1){
                    $(".pre a").removeClass("disabled");
                 }else{
                    $(".pre a").addClass("disabled");
                }
                var insHtml = '<thead><tr>'
                            +'<th>序号</th>'
                            +' <th>姓名</th>'
                            +'<th>反馈内容</th>'
                            +'<th>反馈日期</th>'
                            +'<th>指导医师</th>'
                            +'<th>指导内容</th>'
                            +'<th>指导日期</th>'
                            +'<th>状态</th>'
                            +'</tr>'
                            +'</thead>'
                            +'<tbody>';
                for (var i =0; i < r.data.length;  i++) {
                    var res = r.data[i]
                    phone = res["phone"];
                    insHtml +='<tr onclick="showModal(this)" style="cursor: pointer;">'
                    +'<td dataid="'+res["_id"]+'" dataphone="'+res["phone"]+'" dataidCard="'+res["idCard"]+'">'+ (parseInt(i)+parseInt(1))+'</td>'
                    +'<td>'+res["userName"]+'</td>'
                    var feedC = res["textarea"];
                    if (feedC==undefined){
                        insHtml += '<td></td>'
                    }else{
                        var _feedC = feedC
                        if(feedC.length>10){
                            _feedC = feedC.substring(0,10)+"..."
                        }
                        insHtml += '<td title="'+feedC+'">'+_feedC+'</td>'
                    }
                    insHtml +='<td>'+res["feedTime"]+'</td>'
                    var guidePhysician = res["guidePhysician"];
                    if (guidePhysician==undefined){
                        insHtml += '<td></td>'
                    }else{
                        insHtml += '<td>'+guidePhysician+'</td>'
                    }
                    var replyContent = res["replyContent"];
                    if (replyContent==undefined){
                        insHtml += '<td></td>'
                    }else{
                        var _replyContent = replyContent
                        if(replyContent.length>10){
                            _replyContent = replyContent.substring(0,10)+"..."
                        }
                        insHtml += '<td title="'+replyContent+'">'+_replyContent+'</td>'
                    }
                    var replyTime = res["replyTime"];
                    if (replyTime==undefined){
                        insHtml += '<td></td>'
                    }else{
                        insHtml += '<td>'+replyTime+'</td>'
                    }
                    var status = res["status"];
                    if (status=="0"){
                        insHtml += '<td>未回复</td>'
                    }else{
                        insHtml += '<td>已回复</td>'
                    }
                    insHtml +='</tr>'
                }
                insHtml +='</tbody>'
                if(insHtml!=""){
                    $(".table").html(insHtml);
                }else{
                    $(".table").html('<div class="noData">暂无数据</div>');
                }
            }
        })
    }
</script>
{{end}}